package com.he.DesignPatterns.Responsibility;

/**
 * @description: 抽象处理者类
 * @Author: HCL
 * @Date: 2024/9/3 17:04
 */
public abstract class Handler {
    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_FIVE = 5;

//    该领导处理的请求天数区间
    private Integer numStart;
    private Integer numEnd;

    //声明后续者类(领导的上级领导)
    private Handler nextHandler;

    public Handler(Integer numStart, Integer numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    public Handler(Handler handler) {
        this.nextHandler = handler;
    }

    // 设置上级领导对象
    public void setHandler(Handler nextHandler) {
        this.nextHandler =nextHandler;
    }

    //各级领导处理请假条的方法
    protected abstract void handleLeave(LeaveRequest leaveRequest);

    //提交请假条
    public final void submit(LeaveRequest leaveRequest){
        //该领导先进行审批
        this.handleLeave(leaveRequest);
        //超过了请假天数，有上级领导时，提交给上级领导
        if (leaveRequest.getNum() > this.numEnd && this.nextHandler != null){
            this.nextHandler.submit(leaveRequest);
        }else{
            System.out.println("流程结束");
        }
    }
}
